// import vue from "vue"

export default {
	data: () => {
		return {
			clearAutocompleteListTimeStatus: null,
			AutocompleteList: [],
			searchScrollTop: 0,
			oldSearchScroll: {
				scrollTop: 0
			},
			showClearIcon:false
		}
	},
	methods: {
		clearAutocompleteList() {
			const _self = this
			_self.clearAutocompleteListTimeStatus = setTimeout(() => {
				_self.AutocompleteList = []
			}, 300)
		},
		clearListTimeStatus() {
			clearTimeout(this.clearAutocompleteListTimeStatus)
		},
		getAutocompleteList(keywords) {
			if (keywords.length < 2) {
				this.AutocompleteList = [];
				this.showClearIcon = false
				return false;
			}else{
				this.showClearIcon = true
			}
			let data = this.initNewData();
			data.from = 4038;
			data.location = 4050;
			data.keyword = keywords;
			uni.request({
				url: this.baseConfig.serverURL + 'zhaobiao/SearchAutoCompleteKwdsHandler.ashx',
				data: data,
				method: "POST",
				header: {
					"content-type": "application/x-www-form-urlencoded" //"application/json"
				},
				success: (res) => {
					if (res.statusCode == 200) {
						if (res.data.ret) {
							//获取成功，绑定
							let list = res.data.other2.data;
							if (list && list.length > 0) {
								this.AutocompleteList = list;
								this.searchScrollTop = this.oldSearchScroll.scrollTop
								this.$nextTick(() => {
									this.searchScrollTop = 0
								});
							}
						} else {
							this.AutocompleteList = [];
						}
					} else {
						this.AutocompleteList = [];
					}
				},
				fail: (res) => {
					this.AutocompleteList = [];
				}
			});
		},
		Completeheighthtml(key, cont) {
			if (key === '') {
				return cont;
			}
			var keyarr = key.split(',');
			for (var i = 0; i < keyarr.length; i++) {
				if (keyarr[i] != '') {
					var reg = new RegExp((`(${keyarr[i]})`), "gm");
					var replace = '<text style="color:red;font-weight: bold;" >$1</text>';
					cont = cont.replace(reg, replace)
				}
			}
			return cont;
		},
		searchScroll: function(e) {
			this.oldSearchScroll.scrollTop = e.detail.scrollTop
		},
		clearList() {
			uni.hideKeyboard();
			this.AutocompleteList = [];
		}
	}
}
